package com.itheima.controller;


import com.itheima.anno.Log;
import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result page(StuQueryParam stuQueryParam){
        log.info("分页查询,参数:{}",stuQueryParam);
        PageResult pageResult=studentService.page(stuQueryParam);
        return Result.success(pageResult);
    }

    @Log
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除员工,id:{}",id);
        studentService.deleteById(id);
        return Result.success();
    }

    @Log
    @PostMapping
    public Result add(@RequestBody Student student){
        log.info("添加学生,学生信息:{}",student);
        studentService.add(student);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询学生id为:{}",id);
        Student student=studentService.getInfo(id);
        return Result.success(student);
    }


    @Log
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("更新学生信息:{}",student);
        studentService.update(student);
        return Result.success();
    }

    @Log
    @PutMapping("/violation/{id}/{score}")
    public Result weiji(@PathVariable Integer id,@PathVariable Short score){
        log.info("扣分,学生id:{},扣分:{}",id,score);
        studentService.weiji(id,score);
        return Result.success();
    }
}
